package drds.data_propagate.parse.binlog_event_position_manager;

import drds.data_propagate.entry.position.BinLogEventPosition;
import drds.data_propagate.parse.exception.ParseException;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;


public class MemoryBinLogEventPositionManager extends AbstractBinLogEventPositionManager {

    private Map<String, BinLogEventPosition> taskIdToBinLogEventPositionMap = new ConcurrentHashMap<String, BinLogEventPosition>();

    @Override
    public void start() {
        super.start();
        //taskIdToBinLogEventPositionMap = new MapMaker().makeMap();
    }

    @Override
    public void stop() {
        super.stop();
        taskIdToBinLogEventPositionMap.clear();
    }

    @Override
    public BinLogEventPosition getLatestBinLogEventPosition(String taskId) {
        return taskIdToBinLogEventPositionMap.get(taskId);
    }

    @Override
    public void persistBinLogEventPosition(String taskId, BinLogEventPosition binLogEventPosition) throws ParseException {
        taskIdToBinLogEventPositionMap.put(taskId, binLogEventPosition);
    }

    public Set<String> taskIdSet() {
        return taskIdToBinLogEventPositionMap.keySet();
    }

}
